//
//  TouPiaoButtomView.m
//  GuShiNews
//
//  Created by huachun on 2019/8/26.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "TouPiaoButtomView.h"

#import "LunTanModel.h"

@interface TouPiaoButtomView ()

@end

@implementation TouPiaoButtomView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        
        CALayer *line= [CALayer new];
        line.frame=CGRectMake(0, 0, RECRWITCH, 1);
        line.backgroundColor =backColor.CGColor;
        [self.layer addSublayer:line];
        
        NSArray *linlist = @[@"  点赞",@"  评论",@"  收藏"];
        CGFloat w = RECRWITCH/linlist.count;
        [linlist enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(w*idx, 1, w, 40)];
            button.tag = idx;
            [button setTitle:obj forState:UIControlStateNormal];
            [button addTarget:self action:@selector(chooseindex:) forControlEvents:UIControlEventTouchUpInside];
            [button.titleLabel setFont:[UIFont systemFontOfSize:14]];
            [button setTitleColor:NewsotherColor forState:UIControlStateNormal];
            [self addSubview:button];
            if (idx==0) {
                [button setTitleColor:[JonesClass stringTOColor:@"#515151"] forState:UIControlStateNormal];
                [button setImage:[UIImage imageNamed:@"lun_zan_b"] forState:UIControlStateNormal];
                self.button01 = button;
            }else if (idx==1){
                [button setTitleColor:[JonesClass stringTOColor:@"#515151"] forState:UIControlStateNormal];
                [button setImage:[UIImage imageNamed:@"lun_write_b"] forState:UIControlStateNormal];
                self.button02 = button;
            }else{
                [button setTitleColor:[JonesClass stringTOColor:@"#515151"] forState:UIControlStateNormal];
                [button setImage:[UIImage imageNamed:@"lun_shou_b"] forState:UIControlStateNormal];
                self.button03 = button;
            }
            
            CALayer *linele= [CALayer new];
            linele.frame=CGRectMake(0, 0, 1, NAV_Height-20);
            linele.backgroundColor =backColor.CGColor;
            [button.layer addSublayer:linele];
        }];
        
    }
    return self;
}

- (void)chooseindex:(UIButton *)sender{
    _selectblock(sender.tag);
}

- (void)setModel:(LunTanModel *)Model{
    if (_Model!=Model) {
        _Model = Model;
    }
    
    if ([_Model.zan_count intValue]>0) {
        [self.button01 setTitle:[NSString stringWithFormat:@"  点赞(%@)",_Model.zan_count] forState:UIControlStateNormal];
    }
    
    if ([_Model.ping_count intValue]>0) {
        [self.button02 setTitle:[NSString stringWithFormat:@"  评论(%@)",_Model.ping_count] forState:UIControlStateNormal];
    }
}

@end
